<template>
    <div>
        <!-- tab-top-webview-main -->
		<!-- 滑动导航 -->
       <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<!-- tap 的作用跟click类似  但tap只能用在mui中 -->
						<a v-for="item in cateList" :key="item.id" @tap="getNavList(item.id)" :class="['mui-control-item',item.id==0?'mui-active':'']"  data-wid="tab-top-subpage-1.html">
							{{item.title}}
						</a>
					</div>
				</div>
			</div>
		<!-- 图片内容区 -->
		<ul class="photo-list">
			<!-- tag="li"的作用，让router-link渲染的标签为li，即在浏览器查看代码时看到的是li标签 -->
			<router-link v-for="item in list" :key="item.id" :to="'/home/photoList/photoInfo/'+item.id" tag="li">
				<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">{{item.zhaiyao}}</div>
				</div>
			</router-link>
		</ul>
    </div>
</template>

<script>
//使用导入以下mui，需要添加以下内容
//安装对应包：
// npm install babel-plugin-transform-remove-strict-mode -D
//babelirc 中添加以下内容
// ,"transform-remove-strict-mode"
//{"plugins":[transorm-remove-strict-mode]}

import mui from '../../lib/mui/js/mui.js'
import {Toast} from 'mint-ui'
export default {
	data(){
		return{
			cateList:null,
			list:{}
		}
	},
	mounted() { //页面加载好之后的钩子函数
			mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
	});
	},
	created(){
		this.getAllCategory()
		this.getNavList(0);
	},
	methods: {
		//从后台获取导航栏列表
		getAllCategory(){
				this.$http.get("photocates.json").then(result => {
					if(result.body){
						this.cateList = result.body
					}else{
						Toast("获取数据失败！！！")
					}
				})
		},
		getNavList(id){
			this.$http.get("photos.json").then(result => {
				if(result.body){
					console.log(result.body)
					if (id==0) {
						this.list=result.body
					} else {
						this.list = result.body.filter(item =>{
							if(item.cateid == id){
								return item;
							}
						})
					}
					console.log(this.list)
				}else{
					Toast("获取数据失败！！！")
				}
			})
		}
	},
	
}
</script>

<style lang="scss" scoped>
/* 解决警告加以下样式[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> */
	/* 是chrom 为了提高滑动流畅度 */
	* { touch-action: pan-y; }
	.photo-list{
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom: 0;

		li{
			background-color: #ccc;
			text-align: center;
			margin-bottom: 10px;
			box-shadow: 0 0 9px #999;
			position: relative;
			
			img{
				width: 100%;
				height: 300px;
			}

			image[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}

			 .info {
				 width: 100%;
				color: white;
				text-align: left;
				position: absolute;
				bottom: 0;
				background-color: rgba(0, 0, 0, 0.4);
				max-height: 84px;
				.info-title {
					font-size: 14px;
				}
				.info-body {
					font-size: 13px;
				}
			 }
		}

	}
	
</style>